package com.funfitnessapp;

import java.util.*;
import java.io.*;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class Profile {
        ProfilePerson person;
        
        
        public Profile(String name) {
                person = new ProfilePerson();
                
                //File loading
                try{
                        // Open the file that is the first 
                        // command line parameter
                        FileInputStream fstream = new FileInputStream(name);
                        // Get the object of DataInputStream
                        DataInputStream in = new DataInputStream(fstream);
                        BufferedReader br = new BufferedReader(new InputStreamReader(in));
                        String strLine;
                        //Read File Line By Line
                        if ((strLine = br.readLine()) != null)
                                person.setFirstName(strLine);
                        
                        if ((strLine = br.readLine()) != null)
                                person.setLastName(strLine);

                        if ((strLine = br.readLine()) != null)
                                person.setWeight(Integer.parseInt(strLine));
                        
                        if ((strLine = br.readLine()) != null)
                                person.setIdealWeight(Integer.parseInt(strLine));
                        
                        if ((strLine = br.readLine()) != null)
                                person.setHeightFeet(Integer.parseInt(strLine));
                        
                        if ((strLine = br.readLine()) != null)
                                person.setHeightInches(Integer.parseInt(strLine));
                        
                        if ((strLine = br.readLine()) != null)
                                person.setNumTrophies(Integer.parseInt(strLine));
                        
                        if ((strLine = br.readLine()) != null)
                                person.setMilesRan(Integer.parseInt(strLine));
                        
                        if ((strLine = br.readLine()) != null)
                                person.setNumOfRuns(Integer.parseInt(strLine));
                        
                        if ((strLine = br.readLine()) != null)
                                person.setBmi(Integer.parseInt(strLine));
                        
                        
                        //Close the input stream
                        in.close();

                        person.custToString();
                        
                }catch(Exception ie){
                        try {
                            File file = new File(name);

                            boolean success = file.createNewFile();
                            if (success) {
                                // File did not exist and was created
                            } else {
                                // File already exists
                            }
                        } catch (IOException e) {
                        }
                }
        }
        
       
}